<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
    <title>诊断推荐</title>
    <meta name="decorator" content="default"/>
    <script type="text/javascript">
        $(document).ready(function() {
            //$("#name").focus();
            $("#inputForm").validate({
                submitHandler: function(form){
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function(error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });
        });
    </script>
</head>
<body>
    <ul class="nav nav-tabs">

        <li class="active"><a href="${ctx}/consultation/recommend/form?answerId=${beautyConsultationOrderRecommend.answerId}&&orderId=${beautyConsultationOrderRecommend.orderId}">诊断<shiro:hasPermission name="recommend:beautyConsultationOrderRecommend:edit">${not empty beautyConsultationOrderRecommend.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="recommend:beautyConsultationOrderRecommend:edit">查看</shiro:lacksPermission></a></li>
    </ul><br/>
    <form:form id="inputForm" modelAttribute="beautyConsultationOrderRecommend" action="${ctx}/consultation/recommend/save" method="post" class="form-horizontal">
        <form:hidden path="id"/>
        <sys:message content="${message}"/>     
        <form:hidden path="orderId" value="${beautyConsultationOrderRecommend.orderId}"/>
        <form:hidden path="answerId" value="${beautyConsultationOrderRecommend.answerId}"/>
        <div class="control-group">
            <label class="control-label">诊断结果：</label>
            <div class="controls">
                <form:input path="result" htmlEscape="false" maxlength="1024" class="input-xlarge "/>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">推荐服务：</label>
            <div class="controls">

                <form:textarea  path="service" htmlEscape="false" rows="6" maxlength="1024"  class="input-xlarge " id="service" readonly="true"/>                
                <form:hidden path="serviceId" id="serviceId"/>
                
                <button id="serviceButton" class="btn btn-primary"  type="button">添加服务</button>
                <button id="serviceClear" class="btn btn-primary"  type="button">重置</button>                  
                <script type="text/javascript">
                    $("#serviceButton").click(function(){
                        top.$.jBox.open("iframe:${ctx}/consultation/recommend/serviceList", "选择服务",610,$(top.document).height()-240,{
                            buttons:{"确定分配":"ok", "清除已选":"clear", "关闭":true},submit:function(v, h, f){
                                //var ids = h.find("iframe")[0].contentWindow.pre_ids;
                                //var values = h.find("iframe")[0].contentWindow.ids;
                                //nodes = selectedTree.getSelectedNodes();
                                if (v=="ok"){                                    
                                    h.find("iframe")[0].contentWindow.collectClick();
                                    
                                    var ids = h.find("iframe")[0].contentWindow.ids;
                                    
                                    var values = h.find("iframe")[0].contentWindow.values; 
                                    
                                    if($("#service").val()){
                                        //$("#product").val($("#product").val()+","+values)
                                        
                                        var org=$("#service").val().split(",");
                                        
                                        var add=values.split(",");
                                        
                                        var flag=1;
                                        
                                        for(var i=0;i<add.length;i++){//3243
                                            flag=1;
                                            for(var j=0;j<org.length;j++){//主推商品会员价最低,主推商品,34234
                                                
                                                
                                               if(org[j]==add[i]){

                                                   flag=0;
                                                   break;
                                                   
                                                }                                                                                               
                                            }
                                            if(flag){

                                                $("#service").val($("#service").val()+","+add[i]);
                                            }
                                        }                                       
                                    }else{
                                        $("#service").val(values);
                                    }
                                    
                                    if($("#serviceId").val()){
                                        //$("#product").val($("#product").val()+","+values)
                                        
                                        var org=$("#serviceId").val().split(",");
                                        
                                        var add=ids.split(",");
                                        
                                        var flag=1;
                                        
                                        for(var i=0;i<add.length;i++){//3243
                                            flag=1;
                                            for(var j=0;j<org.length;j++){//主推商品会员价最低,主推商品,34234
                                                
                                                
                                               if(org[j]==add[i]){

                                                   flag=0;
                                                   break;
                                                   
                                                }                                                                                               
                                            }
                                            if(flag){

                                                $("#serviceId").val($("#serviceId").val()+","+add[i]);
                                            }
                                        }                                       
                                    }else{
                                        $("#serviceId").val(ids);
                                    }                                     

                                } else if (v=="clear"){
                                    h.find("iframe")[0].contentWindow.clearAssign();
                                    return false;
                                }
                            }, loaded:function(h){
                                $(".jbox-content", top.document).css("overflow-y","hidden");
                            }
                        });
                    });
                    
                    $("#serviceClear").click(function(){
                        
                        $("#service").val("");
                        $("#serviceId").val("");                        
                    })                    
                </script>                 
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">推荐疗程：</label>
            <div class="controls">

                <form:textarea  path="treat" htmlEscape="false"  rows="6" maxlength="1024" class="input-xlarge " id="treat" readonly="true"/>   

                <form:hidden path="treatId" id="treatId"/>              
                
                <button id="treatButton" class="btn btn-primary"  type="button">添加疗程</button>
                <button id="treatClear" class="btn btn-primary"  type="button">重置</button>                   
                <script type="text/javascript">
                    $("#treatButton").click(function(){
                        top.$.jBox.open("iframe:${ctx}/consultation/recommend/treatList", "选择疗程",610,$(top.document).height()-240,{
                            buttons:{"确定分配":"ok", "清除已选":"clear", "关闭":true},submit:function(v, h, f){
                                //var ids = h.find("iframe")[0].contentWindow.pre_ids;
                                //var values = h.find("iframe")[0].contentWindow.ids;
                                //nodes = selectedTree.getSelectedNodes();
                                if (v=="ok"){
                                    
                                    

                                    
                                    h.find("iframe")[0].contentWindow.collectClick();
                                    
                                    var ids = h.find("iframe")[0].contentWindow.ids;
                                    
                                    var values = h.find("iframe")[0].contentWindow.values; 
                                    
                                    if($("#treat").val()){
                                        //$("#product").val($("#product").val()+","+values)
                                        
                                        var org=$("#treat").val().split(",");
                                        
                                        var add=values.split(",");
                                        
                                        var flag=1;
                                        
                                        for(var i=0;i<add.length;i++){//3243
                                            flag=1;
                                            for(var j=0;j<org.length;j++){//主推商品会员价最低,主推商品,34234
                                                
                                                
                                               if(org[j]==add[i]){

                                                   flag=0;
                                                   break;
                                                   
                                                }                                                                                               
                                            }
                                            if(flag){

                                                $("#treat").val($("#treat").val()+","+add[i]);
                                            }
                                        }                                       
                                    }else{
                                        $("#treat").val(values);
                                    }
                                    
                                    if($("#treatId").val()){
                                        //$("#product").val($("#product").val()+","+values)
                                        
                                        var org=$("#treatId").val().split(",");
                                        
                                        var add=ids.split(",");
                                        
                                        var flag=1;
                                        
                                        for(var i=0;i<add.length;i++){//3243
                                            flag=1;
                                            for(var j=0;j<org.length;j++){//主推商品会员价最低,主推商品,34234
                                                
                                                
                                               if(org[j]==add[i]){

                                                   flag=0;
                                                   break;
                                                   
                                                }                                                                                               
                                            }
                                            if(flag){

                                                $("#treatId").val($("#treatId").val()+","+add[i]);
                                            }
                                        }                                       
                                    }else{
                                        $("#treatId").val(ids);
                                    }       
                                    
                                    //alert($("#treatId").val()+"+"+$("#treat").val());

                                } else if (v=="clear"){
                                    h.find("iframe")[0].contentWindow.clearAssign();
                                    return false;
                                }
                            }, loaded:function(h){
                                $(".jbox-content", top.document).css("overflow-y","hidden");
                            }
                        });
                    });
                    
                    $("#treatClear").click(function(){
                        
                        $("#treat").val("");
                        $("#treatId").val("");                        
                    })
                </script>    
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">推荐产品：</label>
            <div class="controls">

                <form:textarea  path="product" htmlEscape="false" rows="6" maxlength="1024" class="input-xlarge " id="product" readonly="true"/>
              
                <form:hidden path="productId" id="productId"/>
 
                <button id="assignButton" class="btn btn-primary"  type="button">添加产品</button>
                <button id="productClear" class="btn btn-primary"  type="button">重置</button>                
                <script type="text/javascript">
                    $("#assignButton").click(function(){
                        top.$.jBox.open("iframe:${ctx}/consultation/recommend/productList", "选择产品",610,$(top.document).height()-240,{
                            buttons:{"确定分配":"ok", "清除已选":"clear", "关闭":true},submit:function(v, h, f){
                                //var ids = h.find("iframe")[0].contentWindow.pre_ids;
                                //var values = h.find("iframe")[0].contentWindow.ids;
                                //nodes = selectedTree.getSelectedNodes();
                                if (v=="ok"){
                                    
                                    

                                    
                                    h.find("iframe")[0].contentWindow.collectClick();
                                    
                                    var ids = h.find("iframe")[0].contentWindow.ids;
                                    
                                    var values = h.find("iframe")[0].contentWindow.values; 
                                    

                                    
                                    if($("#product").val()){
                                    	//$("#product").val($("#product").val()+","+values)
                                    	
                                    	var org=$("#product").val().split(",");
                                    	
                                    	var add=values.split(",");
                                    	
                                        var flag=1;
                                    	
                                        for(var i=0;i<add.length;i++){//3243
                                        	flag=1;
                                        	for(var j=0;j<org.length;j++){//主推商品会员价最低,主推商品,34234
                                        		
                                        		
                                               if(org[j]==add[i]){

                                            	   flag=0;
                                            	   break;
                                                   
                                                }                                       		                                        		
                                        	}
                                        	if(flag){

                                                $("#product").val($("#product").val()+","+add[i]);
                                        	}
                                        }                                   	
                                    }else{
                                    	$("#product").val(values);
                                    }
                                    
                                    if($("#productId").val()){
                                        //$("#product").val($("#product").val()+","+values)
                                        
                                        var org=$("#productId").val().split(",");
                                        
                                        var add=ids.split(",");
                                        
                                        var flag=1;
                                        
                                        for(var i=0;i<add.length;i++){//3243
                                            flag=1;
                                            for(var j=0;j<org.length;j++){//主推商品会员价最低,主推商品,34234
                                                
                                                
                                               if(org[j]==add[i]){

                                                   flag=0;
                                                   break;
                                                   
                                                }                                                                                               
                                            }
                                            if(flag){

                                                $("#productId").val($("#productId").val()+","+add[i]);
                                            }
                                        }
                                        
                                        //alert($("#productId").val());
                                    }else{
                                        $("#productId").val(ids);
                                    }
                                    
                                    //alert($("#product").val()+"+"+$("#productId").val());

                                } else if (v=="clear"){
                                    h.find("iframe")[0].contentWindow.clearAssign();
                                    return false;
                                }
                            }, loaded:function(h){
                                $(".jbox-content", top.document).css("overflow-y","hidden");
                            }
                        });
                    });
                    
                    
                    $("#productClear").click(function(){
                    	
                        $("#product").val("");
                        $("#productId").val("");
                    })
                </script>
              
            </div>
        </div>                
        <div class="form-actions">
            <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;
            <input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
        </div>
    </form:form>
</body>
</html>